package com.googlecode.garbagecan.cxfstudy.security;

import java.util.HashMap;
import java.util.Map;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;

public class MyServer {

	private static final String address = "http://localhost:9000/ws/security/userService";

	public static void main(String[] args) throws Exception {
		JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
		factoryBean.getInInterceptors().add(new LoggingInInterceptor());
		factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());

		Map<String, Object> props = new HashMap<String, Object>();
		props.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
		props.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
		props.put(WSHandlerConstants.PW_CALLBACK_CLASS, ServerUsernamePasswordHandler.class.getName());
		WSS4JInInterceptor wss4JInInterceptor = new WSS4JInInterceptor(props);
		factoryBean.getInInterceptors().add(wss4JInInterceptor);
		
		factoryBean.setServiceClass(UserServiceImpl.class);
		factoryBean.setAddress(address);
		factoryBean.create();
	}
}
